package com.itetchologyandenglish.home.service.Impl;

import com.itetchologyandenglish.home.enetity.Auth;
import com.itetchologyandenglish.home.mapper.ResourceMapper;
import com.itetchologyandenglish.home.service.AuthService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AuthServiceImpl implements AuthService {
    @Resource
    ResourceMapper resourceMapper;
    @Override
    public List<Auth> list() {
        return resourceMapper.list();
    }

    @Override
    public int addAuthRole(Integer roleId, Integer[] authIds) {
        Map<String,Integer> authRoleMap;
        List<Map<String, Integer>> list=new ArrayList<>();
        for(int i=0;i<authIds.length;i++){
            authRoleMap=new HashMap<>();
            authRoleMap.put("roleId",roleId);
            authRoleMap.put("authId",authIds[i]);
            System.out.println(authIds[i]);
            list.add(authRoleMap);
        }
        return resourceMapper.addAuthRole(list);
    }

    @Override
    public Auth getAuthById(Integer id) {
        return resourceMapper.getAuthById(id);
    }

    @Override
    public boolean updateAuth(Auth auth) {
        return resourceMapper.updateAuth(auth)>0? true:false;
    }

    @Override
    public boolean removeAuth(Integer id) {
        return resourceMapper.removeAuth(id)>0?true:false;
    }

    @Override
    public List<Integer> getAuthByRoleId(Integer id) {
        return resourceMapper.getAuthByRoleId(id);
    }

    @Override
    public int delAuthRole(Integer roleId) {
        return resourceMapper.delRoleAuth(roleId);
    }

    @Override
    public boolean addAuth(Auth auth) {
        return resourceMapper.addAuth(auth)>0?true:false;
    }
}
